-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[LibraryImportGenerator] Use basic forwarder in down-level support if any parameters can't be marshalled #104416
Merged
elinor-fung
merged 4 commits into
dotnet:main
from
elinor-fung:library-import-partial-forward
Jul 8, 2024
Merged
[LibraryImportGenerator] Use basic forwarder in down-level support if any parameters can't be marshalled #104416
elinor-fung
merged 4 commits into
dotnet:main
from
elinor-fung:library-import-partial-forward
Jul 8, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… any parameters can't be marshalled
/azp run runtime-libraries-coreclr outerloop |
Azure Pipelines successfully started running 1 pipeline(s). |
...ibraries/System.Runtime.InteropServices/gen/LibraryImportGenerator/LibraryImportGenerator.cs
Outdated
Show resolved
Hide resolved
...raries/System.Runtime.InteropServices/gen/LibraryImportGenerator/PInvokeStubCodeGenerator.cs
Outdated
Show resolved
Hide resolved
...raries/System.Runtime.InteropServices/gen/LibraryImportGenerator/PInvokeStubCodeGenerator.cs
Outdated
Show resolved
Hide resolved
AaronRobinsonMSFT
approved these changes
Jul 5, 2024
5 tasks
Co-authored-by: Aaron Robinson <arobins@microsoft.com>
AaronRobinsonMSFT
approved these changes
Jul 8, 2024
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Alternative to #103973 (and #104246)
In down-level support, when determining marshalling generators for types, we fall back to just forwarding the parameter without erroring. This means that we end up generating a stub that marshal some parameters and just silently forwards others when all of these are true:
ITypeBasedMarshallingInfoProvider
as missing marshalling supportThis is not a problem in non-down-level scenarios, as we error if we can't marshal any parameters. This is also not a problem if any parameters are identified as unsupported via an
ITypeBasedMarshallingInfoProvider
, as we do correctly check that case and simply forward toDllImport
.This change makes it so that in down-level scenarios, if any type falls back to forwarding, we print a basic
DllImport
instead of a stub with mixed marshalling and forwarding.We have existing tests for validating that any unsupported type resulted in a forwarder even when other types were supported:
runtime/src/libraries/System.Runtime.InteropServices/tests/LibraryImportGenerator.UnitTests/Compiles.cs
Lines 524 to 527 in 69f7006
However, they only used types that were explicitly flagged as not supported by an
ITypeBasedMarshallingInfoProvider
that handled the type. They were also usingSafeHandle
as the non-blittable type that was supported down-level, but that is no longer the case in main (has been removed in .NET 9 so that we only supporting marshalling viaSafeHandleMarshaller
).